#!/usr/bin/env node

const { spawn } = require('child_process');
const path = require('path');

console.log('启动WebSocket服务器模拟器...');

// 启动WebSocket服务器
const wsServer = spawn('node', ['websocket-server-mock.js'], {
  stdio: 'inherit',
  cwd: __dirname
});

wsServer.on('error', (error) => {
  console.error('启动WebSocket服务器失败:', error);
  process.exit(1);
});

wsServer.on('close', (code) => {
  console.log(`WebSocket服务器已退出，退出码: ${code}`);
  process.exit(code);
});

// 处理进程退出
process.on('SIGINT', () => {
  console.log('\n正在关闭WebSocket服务器...');
  wsServer.kill('SIGINT');
});

process.on('SIGTERM', () => {
  console.log('\n正在关闭WebSocket服务器...');
  wsServer.kill('SIGTERM');
});

console.log('WebSocket服务器已启动，按 Ctrl+C 停止'); 